package cn.edu.hit.education.action;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.plugin.AbstractUIPlugin;

import cn.edu.hit.education.dialog.ProcessDialog;
import cn.edu.hit.education.pojo.Process;
import cn.edu.hit.education.service.IProcessService;
import cn.edu.hit.education.view.CourseExploreView;
import educationschedule.Activator;
import educationschedule.Application;

public class UpdateProcessAction extends Action {
	private CourseExploreView viewPart;
	IProcessService processService = (IProcessService)Application.applicationContext.getBean("processServiceImpl");
	private int processId;
	
	public UpdateProcessAction(CourseExploreView viewPart,int processId){
		this.setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/toolbar/course_code_16px.png"));
		this.setToolTipText("修改过程");
		this.setText("修改过程");
		this.viewPart = viewPart;
		this.processId = processId;
	}
	
	@Override
	public void run() {
		Shell parentShell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
		ProcessDialog processDialog = new ProcessDialog(parentShell);
		Process process = processService.queryProcessByPrimaryKey(processId);
		processDialog.setProcess(process);
		if(IDialogConstants.OK_ID == processDialog.open()){
			int count = processService.update(process);
			if(count > 0){
				viewPart.refreshUpdateData(process);
			}
		}
		super.run();
	}

	

}
